<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Settings extends CI_Controller {
	
	var $eData = '';
	
	function __construct()
	{
		parent::__construct();
		$this->thor->loginstate();
	}

	function index()
	{
		$this->eData['eType'] = '';
		
		$this->load->library('form_validation');
		$this->form_validation->set_rules('title', 'Site name', 'trim|max_length[200]|xss_clean');
		$this->form_validation->set_rules('email', 'E-mail', 'trim|max_length[200]|xss_clean');
		$this->form_validation->set_rules('smtphost', 'Smtp Host', 'trim|max_length[200]|xss_clean');
		$this->form_validation->set_rules('smtpuser', 'Smtp Username', 'trim|max_length[200]|xss_clean');
		$this->form_validation->set_rules('smtppass', 'Smtp Password', 'trim|max_length[200]|xss_clean');
		$this->form_validation->set_rules('smtpport', 'Smtp Port', 'trim|max_length[200]|xss_clean');
		$this->form_validation->set_rules('hometitle', 'Home Title', 'trim|max_length[200]|xss_clean');
		$this->form_validation->set_rules('homekeyword', 'Keywords', 'trim|max_length[200]|xss_clean');
		$this->form_validation->set_rules('homedescribe', 'Describe', 'trim|max_length[200]|xss_clean');
		if ($this->form_validation->run() == TRUE)
		{
			$eDate['s_title']         = $this->input->post("title");
			$eDate['s_email']         = $this->input->post("email");
			$eDate['s_smtphost']      = $this->input->post("smtphost");
			$eDate['s_smtpuser']      = $this->input->post("smtpuser");
			$eDate['s_smtppass']      = $this->input->post("smtppass");
			$eDate['s_smtpport']      = $this->input->post("smtpport");
			$eDate['s_hometitle']     = $this->input->post("hometitle");
			$eDate['s_htmlkeyword']   = $this->input->post("homekeyword");
			$eDate['s_htmldescribe']  = $this->input->post("homedescribe");
			
			$this->db->update('settings', $eDate);
			
			$this->db->select('s_id as id, s_title as title, s_phone as phone, s_fax as fax, s_email as email, s_mobile as mobile, s_address as address, s_hometitle as hometitle, s_htmlkeyword as htmlkeyword, s_htmldescribe as htmldescribe, s_smtphost as smtphost, s_smtpuser as smtpuser, s_smtppass as smtppass, s_smtpport as smtpport');
			$eSettings = $this->db->get('settings')->row();
			$this->thor->save_file($eSettings, 'settings');
			
			echo '<script type="text/javascript">
			alert("Successfully saved.");
			window.location.href = "'.site_url('mang/settings').'";
			</script>';
		}
		
		$this->eData['eSettings'] = $this->db->get('settings')->row();
		$this->load->view('mang/settings', $this->eData);
	}
}